#include <iostream>
#include <ctime>
#include <string>
using namespace std;

class User {
private:
	string userName;
public:
	User(string userName) {
		this->userName = userName;
	}
	string greet() {
		return "Hi, " + userName;
	}
};

class Time {
private:
	time_t now;
	int getHour(time_t now) {
		tm* ltm = localtime(&now);
		return ltm->tm_hour;
	}
public:
	Time(time_t now) {
		this->now = now;
	}
	string greet() {
		int hour = getHour(now);
		string word;
		if (hour > 6 && hour <= 12) {
			word = "Good morning! ";
		}
		else if (hour > 12 && hour <= 19) {
			word = "Good afternoon! ";
		}
		else {
			word = "Good night! ";
		}
		return word;
	}
};

string sayHello(time_t now, string userName) {
	User* user = new User(userName);
	Time* time = new Time(now);
	return user->greet() + ". " + time->greet();
}

int main() {
	time_t now = time(0);
	string user = "John";
	cout << sayHello(now, user) << endl;

	tm* morning = localtime(&now);
	morning->tm_hour = 7;
	time_t am = mktime(morning);
	cout << sayHello(am, user) << endl;

	tm* afternoon = localtime(&now);
	afternoon->tm_hour = 13;
	time_t pm = mktime(afternoon);
	cout << sayHello(pm, user) << endl;

	tm* night = localtime(&now);
	night->tm_hour = 20;
	time_t nt = mktime(night);
	cout << sayHello(nt, user) << endl;

	return 0;
}